//
//  UIBarButtonItem+Extension.m
//  MyMicroBlog
//
//  Created by Apple on 16/9/21.
//  Copyright © 2016年 Apple. All rights reserved.
//

#import "UIBarButtonItem+Extension.h"
#import "UIView+Extension.h"
@implementation UIBarButtonItem (Extension)

+(instancetype)itemWithTitle:(NSString *)title andImageName:(NSString *)imageName andTarget:(id)target andAction:(SEL)action{
    UIBarButtonItem *btnItem = [[self alloc]init];
    UIButton *btn = [[UIButton alloc]init];
    if (imageName != nil) {
        [btn setImage:[UIImage imageNamed:imageName] forState:UIControlStateNormal];
    }
    if (target && action) {
        [btn addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
    }
    [btn setTitle:title forState:UIControlStateNormal];
    //设置文字颜色
    [btn setTitleColor:[UIColor darkGrayColor] forState:UIControlStateNormal];
    [btn setTitleColor:[UIColor orangeColor] forState:UIControlStateHighlighted];
    //文字大小
    btn.titleLabel.font = [UIFont systemFontOfSize:14];
    btnItem.customView = btn;
    [btn sizeToFit];
    
    return btnItem;
}

@end
